<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title data-i18n='resources.title_distributeAnalysis'></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" include="iclient-leaflet-css" src="../../dist/leaflet/include-leaflet.js"></script>
</head>

<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
    <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
    <div id="loading">....</div>
    <script>
        var host = window.isLocal ? window.server : "https://iserver.supermap.io";
        var map, url = host + "/iserver/services/map-world/rest/maps/World";
        map = L.map('map', {
            preferCanvas: true,
            crs: L.CRS.EPSG4326,
            center: [40.75, -73.95],
            maxZoom: 18,
            zoom: 12
        });
        var baseLayer = new L.supermap.TiledMapLayer(url).addTo(map);

        var control = L.control.layers().addTo(map).setPosition('topleft').addBaseLayer(baseLayer, 'baseLayer');
        var distributedHost = window.isLocal ? window.server : "https://iserver.supermap.io";
        var distributedAnalystUrl = distributedHost + "/iserver/services/distributedanalyst/rest/v1/jobs";
        
        L.supermap.SecurityManager.registerToken(distributedAnalystUrl, window.exampleToken);

        var distributedAnalysis = new L.supermap.Components.DistributedAnalysis(distributedAnalystUrl);
        distributedAnalysis.addTo(map);


        distributedAnalysis.on("analysissucceeded", function (e) {
            control.addOverlay(e.layer, e.name);
        })
        distributedAnalysis.on("layersremoved", function (e) {
            for (var i in e.layers) {
                control.removeLayer(e.layers[i]);
            }
        })
    </script>
</body>

</html>